using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace LHS.Win
{
    public class ImageCombo : ComboBox
    {
        // Fields
        private ImageList imgs = new ImageList();

        // Methods
        public ImageCombo()
        {
            base.DrawMode = DrawMode.OwnerDrawFixed;
        }

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            if (e.Index < 0)
            {
                e.Graphics.DrawString(this.Text, e.Font, new SolidBrush(e.ForeColor), (float)(e.Bounds.Left + this.imgs.ImageSize.Width), (float)e.Bounds.Top);
            }
            else if (base.Items[e.Index].GetType() == typeof(ImageComboItem))
            {
                ImageComboItem item = (ImageComboItem)base.Items[e.Index];
                Color color = (item.ForeColor != Color.FromKnownColor(KnownColor.Transparent)) ? item.ForeColor : e.ForeColor;
                Font font = item.Mark ? new Font(e.Font, FontStyle.Bold) : e.Font;
                if (item.ImageIndex != -1)
                {
                    this.ImageList.Draw(e.Graphics, e.Bounds.Left, e.Bounds.Top, item.ImageIndex);
                    e.Graphics.DrawString(item.Text, font, new SolidBrush(color), (float)(e.Bounds.Left + this.imgs.ImageSize.Width), (float)e.Bounds.Top);
                }
                else
                {
                    e.Graphics.DrawString(item.Text, font, new SolidBrush(color), (float)(e.Bounds.Left + this.imgs.ImageSize.Width), (float)e.Bounds.Top);
                }
            }
            else
            {
                e.Graphics.DrawString(base.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), (float)(e.Bounds.Left + this.imgs.ImageSize.Width), (float)e.Bounds.Top);
            }
            base.OnDrawItem(e);
        }

        // Properties
        public ImageList ImageList
        {
            get
            {
                return this.imgs;
            }
            set
            {
                this.imgs = value;
            }
        }
    }


}
